package com.fahai.web.service.impl;

import com.fahai.common.PageVo;
import com.fahai.web.dao.*;
import com.fahai.web.service.LawyerTxService;
import com.fahai.web.vo.PayFlowQueryVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;

/**
 * today
 */
@Service
@Transactional(rollbackFor = DataAccessException.class)
public class LawyerTxServiceImpl implements LawyerTxService {

    @Autowired
    LawyerTxDao lawyerTXDao;

    @Autowired
    PayFlownoDao dao_payflow;

    @Autowired
    LawyerInfoDao lawyerInfoDao;


    /**
     * 分页查询律师的提现记录
     * @param lawyername
     * @param lawyerPhone
     * @param beginTime
     * @param endTime
     * @param txStats
     * @param pageVo
     * @return
     */
    @Override
    public PageVo findLawyerTXList(String lawyername, String lawyerPhone, String beginTime, String endTime, Integer txStats,Integer orderBy, PageVo pageVo) {

        Page<HashMap<String,Object>> page = PageHelper.startPage(pageVo.getPageNum(), pageVo.getPageSize());
        List<HashMap<String,Object>> getData =lawyerTXDao.selectList( lawyername,  lawyerPhone,  beginTime,  endTime,  txStats,orderBy);
        pageVo.setResult(getData);
        pageVo.setTotal(new Long(lawyerTXDao.selectListCount(lawyername,  lawyerPhone,  beginTime,  endTime,  txStats)));

        return pageVo;
    }

    /**
     * 分页查询用户充值记录
     * @param uphone
     * @param beginTime
     * @param endTime
     * @param orderPayState
     * @return
     */
    @Override
    public PageVo findPayFlownoList(String uphone, String beginTime, String endTime, Integer orderPayState,Integer orderBy,PageVo pageVo) {
        Page<HashMap<String,Object>> page = PageHelper.startPage(pageVo.getPageNum(), pageVo.getPageSize());
        List<HashMap<String,Object>> getData = dao_payflow.selectpayflowList( uphone,  beginTime,  endTime,  orderPayState,orderBy);
        pageVo.setResult(getData);
        pageVo.setTotal(new Long(dao_payflow.selectListCount(uphone,  beginTime,  endTime, orderPayState)));
        return pageVo;
    }


    /**
     * 处理律师提现的操作
     * @param txId
     * @param returnNum
     * @param remak
     */
    @Override
    public void updateLawyerTxHandle(Integer txId,String returnNum, String remak) {

        HashMap<String,Object>  ltxMap=lawyerTXDao.selectOneData(txId);

        lawyerTXDao.updateHandleLawyerTx(txId,returnNum,remak);

        lawyerInfoDao.updateTxMoney((Integer) ltxMap.get("lawyerid"),(Integer)ltxMap.get("tx_money"));

    }

    /**
     * 查询律师提现记录数据
     * @param lawyername
     * @param lawyerPhone
     * @param beginTime
     * @param endTime
     * @param txStats
     * @param orderBy
     * @return
     */
    @Override
    public List<HashMap<String,Object>> excelLawyerWithList(String lawyername, String lawyerPhone, String beginTime, String endTime, Integer txStats, Integer orderBy) {


        List<HashMap<String,Object>> getData =lawyerTXDao.selectList( lawyername,  lawyerPhone,  beginTime,  endTime,  txStats,orderBy);


        return getData;
    }

    /**
     * 查询用户支付的记录
     * @param uphone
     * @param beginTime
     * @param endTime
     * @param orderPayState
     * @param orderBy
     * @return
     */
    @Override
    public List<HashMap<String, Object>> excelPayList(String uphone, String beginTime, String endTime, Integer orderPayState, Integer orderBy) {

        List<HashMap<String,Object>> getData = dao_payflow.selectpayflowList( uphone,  beginTime,  endTime,  orderPayState,orderBy);

        return getData;
    }

    /**
     * 返回充值成功的总金额
     *
     * @param uphone
     * @param beginTime
     * @param endTime
     * @param pageVo
     * @return
     */
    @Override
    public PayFlowQueryVO getTotalMoney(PayFlowQueryVO conditionvo, PageVo pageVo) {
       PayFlowQueryVO  vo = dao_payflow.getTotalMoney(conditionvo);
        return vo;
    }
}

